package com.fzrskj.cloud.free.sys.utils;

import com.fzrskj.cloud.free.core.enums.DicParamEnum;
import com.fzrskj.cloud.free.dic.utils.DicParamUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * AgentRequestUtils.
 *
 * @author zj.
 *         Created on 2019/5/10 0010.
 */
public class IndexStaticUtils {
    /**
     * 首页跳转.
     */
    public static void toTemplateIndex(HttpServletRequest request, HttpServletResponse response, String uri) {
        if ("/".equals(uri) || "".equals(uri) || "/index.html".equals(uri)) {
            String tmp = DicParamUtils.getParamValue(DicParamEnum.TEMPLATE_KEY.getVal());
            if(tmp.endsWith("/")) {
                tmp = tmp.substring(0, tmp.length()-1);
            }
            String path = tmp + "-index.html";
            try {
                String fullAddress = request.getScheme() + "://" + request.getServerName();
                if (request.getServerPort() != 443 && request.getServerPort() != 80) {
                    fullAddress += ":" + request.getServerPort();
                }
                fullAddress += path;
                System.out.print(fullAddress);
                System.out.print(request.getRemoteUser());
                response.sendRedirect(fullAddress);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
